package com.awanp3.nimbus.common.json.context;

import com.awanp3.nimbus.common.core.utils.ObjectUtils;

import java.util.TimeZone;

/**
 * 时区上下文工具类
 *
 * @author 20014170
 */
public class TimeZoneContextHolder {
    private static final ThreadLocal<TimeZone> TIME_ZONE_HOLDER = new ThreadLocal<>();

    public static void setTimeZone(TimeZone timeZone) {
        TIME_ZONE_HOLDER.set(timeZone);
    }

    public static TimeZone getTimeZone() {
        TimeZone zone = TIME_ZONE_HOLDER.get();
        if (ObjectUtils.isEmpty(zone)) {
            return TimeZone.getDefault();
        }
        return zone;
    }

    public static void clear() {
        TIME_ZONE_HOLDER.remove();
    }
}
